package com.huawei.appgallery.forum.cards.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.forum.base.card.bean.User;
import huawei.widget.HwTextView;
import o.azb;
import o.bsp;
import o.bsu;
import o.bsy.a;
import o.bsy.b;
import o.bsy.c;
import o.bto;
import o.btr;
import o.cgy;

public class UserInfoTextView extends LinearLayout {
    private boolean ʻ = false;
    private int ʼ;
    private boolean ʽ = false;
    private ImageView ˊ;
    private e ˊॱ;
    private HwTextView ˋ;
    private int ˋॱ = 0;
    private HwTextView ˎ;
    private Context ˏ;
    private boolean ˏॱ;
    private HwTextView ॱ;
    private TextView ॱॱ;
    private int ᐝ = 0;

    public interface e {
        void ˊ(int i);
    }

    public void setFromBuoy(boolean z) {
        this.ˏॱ = z;
    }

    public int ˎ() {
        return this.ˋॱ;
    }

    public void setShowModeratorStamp(boolean z) {
        this.ʻ = z;
    }

    public void setShowHostStamp(boolean z) {
        this.ʽ = z;
    }

    public void setHostPriority(int i) {
        this.ᐝ = i;
    }

    public void setModeratorStampPriority(int i) {
        this.ˋॱ = i;
    }

    public void setUserFakeViewChangeListener(e eVar) {
        this.ˊॱ = eVar;
    }

    public void setFakeView(TextView textView) {
        this.ॱॱ = textView;
    }

    public UserInfoTextView(Context context) {
        super(context);
        ˏ(context);
    }

    public UserInfoTextView(Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        ˏ(context);
    }

    public UserInfoTextView(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˏ(context);
    }

    private void ˏ(Context context) {
        this.ˏ = context;
        View inflate = ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(b.ʽॱ, this);
        this.ˋ = (HwTextView) inflate.findViewById(c.ˊʽ);
        this.ˊ = (ImageView) inflate.findViewById(c.ˋʽ);
        this.ॱ = (HwTextView) inflate.findViewById(c.ˋʻ);
        this.ˎ = (HwTextView) inflate.findViewById(c.ˏͺ);
    }

    public HwTextView ˊ() {
        return this.ˋ;
    }

    public HwTextView ˋ() {
        return this.ˎ;
    }

    public HwTextView ॱ() {
        return this.ॱ;
    }

    public void setNickNameTextSize(float f) {
        this.ˋ.setTextSize(0, f);
    }

    public void setData(User user) {
        boolean z = false;
        if (user != null) {
            boolean z2;
            int dimensionPixelOffset;
            this.ˋ.setText(user.ˋ());
            if (user.ʻ()) {
                this.ˊ.setVisibility(0);
                this.ˊ.setImageResource(a.ʻ);
                z2 = true;
            } else if (user.ᐝ()) {
                this.ˊ.setVisibility(0);
                this.ˊ.setImageResource(a.ॱॱ);
                z2 = true;
            } else {
                this.ˊ.setVisibility(8);
                z2 = false;
            }
            if (z2) {
                dimensionPixelOffset = this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ʽॱ) + this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ॱˎ);
            } else {
                dimensionPixelOffset = 0;
            }
            btr ˏ = ˏ(user);
            boolean z3 = ˏ != null;
            if (z3) {
                this.ॱ.setVisibility(8);
                this.ˎ.setVisibility(0);
            } else {
                if (cgy.ˎ(user.ˏ())) {
                    this.ॱ.setVisibility(8);
                } else {
                    this.ॱ.setVisibility(0);
                    this.ॱ.setText(user.ˏ());
                    z = true;
                }
                this.ˎ.setVisibility(8);
            }
            dimensionPixelOffset = (ˏ() - dimensionPixelOffset) - ˎ(z, z3, z2);
            if (z3) {
                ˏ(user, ˏ, dimensionPixelOffset);
            } else {
                ॱ(user, z, dimensionPixelOffset);
            }
        }
    }

    private int ˎ(boolean z, boolean z2, boolean z3) {
        if (!z && !z2) {
            return 0;
        }
        int dimensionPixelOffset;
        if (z3) {
            dimensionPixelOffset = this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ʻॱ);
        } else {
            dimensionPixelOffset = this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ॱˎ);
        }
        if (z) {
            ((LayoutParams) this.ॱ.getLayoutParams()).leftMargin = dimensionPixelOffset;
            return dimensionPixelOffset;
        }
        ((LayoutParams) this.ˎ.getLayoutParams()).leftMargin = dimensionPixelOffset;
        return dimensionPixelOffset;
    }

    private void ˏ(User user, btr o_btr, int i) {
        int ˏ;
        int ˏ2 = bsp.ˏ(this.ˋ, user.ˋ());
        if (o_btr != null) {
            ˏ = bsp.ˏ(this.ˎ, getContext().getResources().getString(o_btr.ˎ()));
            int dimensionPixelOffset = getContext().getResources().getDimensionPixelOffset(o.bsy.e.ˌ);
            ˏ = ˏ > dimensionPixelOffset ? i - dimensionPixelOffset : i - ˏ;
        } else {
            ˏ = i;
        }
        this.ˋ.setMaxWidth(ˏ);
        if (ˏ > ˏ2) {
            ˋ(ˏ2);
        } else {
            ˋ(ˏ);
        }
    }

    private void ॱ(User user, boolean z, int i) {
        int ˏ = bsp.ˏ(this.ˋ, user.ˋ());
        if (z) {
            int i2 = i / 2;
            i = i2 + ॱ(bsp.ˏ(this.ॱ, user.ˏ()), i2);
            this.ॱ.setMaxWidth(i2 + ॱ(ˏ, i2));
        }
        this.ˋ.setMaxWidth(i);
        if (i > ˏ) {
            ˋ(ˏ);
        } else {
            ˋ(i);
        }
    }

    private void ˋ(int i) {
        if (this.ॱॱ == null) {
            return;
        }
        if (this.ˊॱ != null) {
            this.ˊॱ.ˊ(i);
        } else {
            this.ॱॱ.setWidth(i);
        }
    }

    private int ॱ(int i, int i2) {
        if (i > i2) {
            return 0;
        }
        return i2 - i;
    }

    public int ˏ() {
        if (this.ʼ <= 0) {
            if (this.ˏॱ) {
                this.ʼ = (bsu.ॱ(this.ˏ) - (this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ʿ) * 3)) - this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ˎˎ);
            } else {
                this.ʼ = (azb.ॱ(this.ˏ) - (this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ʿ) * 3)) - this.ˏ.getResources().getDimensionPixelOffset(o.bsy.e.ˎˎ);
            }
        }
        return this.ʼ;
    }

    public void setContentWidth(int i) {
        this.ʼ = i;
    }

    private btr ˏ(User user) {
        Object obj;
        Object obj2 = 1;
        Object obj3 = (this.ʽ && user.ʽ()) ? 1 : null;
        if (this.ʻ && user.ॱॱ()) {
            obj = 1;
        } else {
            obj = null;
        }
        if (obj3 == null && obj == null) {
            return null;
        }
        if (obj3 == null || obj == null) {
            obj2 = obj;
        } else {
            if ((this.ᐝ > this.ˋॱ ? 1 : null) != null) {
                obj2 = null;
            }
        }
        if (obj2 != null) {
            return ˏ(10);
        }
        return ˏ(11);
    }

    private btr ˏ(int i) {
        btr ˊ = bto.ˊ(i);
        if (ˊ != null) {
            Context context = this.ˎ.getContext();
            this.ˎ.setTextColor(context.getResources().getColor(ˊ.ˊ()));
            this.ˎ.setText(ˊ.ˎ());
            this.ˎ.setBackground(context.getResources().getDrawable(ˊ.ॱ()));
        }
        return ˊ;
    }

    public void setUserNickNameColor(int i) {
        this.ˋ.setTextColor(i);
    }

    public void setStampTextViewColor(int i) {
        this.ˎ.setTextColor(i);
    }

    public void setUserDutiesViewColor(int i) {
        this.ॱ.setTextColor(i);
    }

    public void setFakeViewColor(int i) {
        this.ॱॱ.setTextColor(i);
    }
}
